package com.leps.nq.tx.controller;

import com.leps.nq.common.aspect.Log;
import com.leps.nq.common.enums.BusinessType;
import com.leps.nq.common.vo.PageVo;
import com.leps.nq.common.vo.R;
import com.leps.nq.common.vo.RBuilder;
import com.leps.nq.tx.entity.ReadHistory;
import com.leps.nq.tx.service.IReadHistoryService;
import com.leps.nq.tx.vo.CreateLiquidVo;
import com.leps.nq.tx.vo.LiquidQueryModel;
import com.leps.nq.tx.vo.UpdateLiquidVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 手动液位管理接口，PLC通信失败的补偿措施
 */
@RestController
@Api(tags = "实时液位管理")
@RequestMapping("/liquid")
public class LiquidLevelController {
    @Autowired
    IReadHistoryService readHistoryService;

    @ApiOperation("手动添加泵实时液位")
    @PostMapping
    @Log(title = "实时液位", businessType = BusinessType.INSERT)
    public R save(@RequestBody CreateLiquidVo vo) {
        this.readHistoryService.addLiquid(vo);
        return RBuilder.ok();
    }

    @ApiOperation("查询泵实时液位列表")
    @GetMapping
    public R<PageVo<ReadHistory>> list(LiquidQueryModel queryModel) {
        PageVo<ReadHistory> vo = this.readHistoryService.pageLiquidByQueryModel(queryModel);
        return RBuilder.ok(vo);
    }

    @ApiOperation("删除实时液位")
    @DeleteMapping
    @Log(title = "实时液位", businessType = BusinessType.DELETE)
    public R remove(@RequestBody List<Long> id) {
        this.readHistoryService.removeBatchByIds(id);
        return RBuilder.ok();
    }

    @ApiOperation("修改实时液位")
    @PutMapping
    @Log(title = "实时液位", businessType = BusinessType.UPDATE)
    public R update(@RequestBody UpdateLiquidVo vo) {
        ReadHistory h = new ReadHistory();
        h.setReadId(vo.getReadId());
        h.setDataValue(vo.getLiquid());
        this.readHistoryService.updateById(h);
        return RBuilder.ok();
    }
}

